#!/usr/bin/env python3
"""调试向量存储管理器"""
from pathlib import Path
import sys
project_root = Path(__file__).parent.parent
sys.path.append(str(project_root))
from core.vector_store import vector_store_manager
from core.embedding_manager import embedding_manager

def debug_vector_store():
    print("=== 调试向量存储管理器 ===")
    
    # 检查向量存储对象
    print(f"向量存储对象: {vector_store_manager.vector_store}")
    print(f"向量存储类型: {type(vector_store_manager.vector_store)}")
    
    if vector_store_manager.vector_store:
        try:
            # 尝试访问_collection属性
            collection = vector_store_manager.vector_store._collection
            print(f"集合对象: {collection}")
            print(f"集合类型: {type(collection)}")
            
            # 尝试获取计数
            count = collection.count()
            print(f"文档数量: {count}")
            
        except Exception as e:
            print(f"访问集合时出错: {e}")
            import traceback
            traceback.print_exc()
    
    # 测试嵌入模型
    print(f"\n=== 嵌入模型测试 ===")
    print(f"嵌入管理器就绪: {embedding_manager.is_ready()}")
    current_model = embedding_manager.get_current_model()
    print(f"当前嵌入模型: {current_model}")
    print(f"嵌入模型类型: {type(current_model)}")
    
    # 尝试直接使用向量存储
    print(f"\n=== 直接测试向量存储 ===")
    if vector_store_manager.vector_store:
        try:
            # 尝试添加一个简单的文本
            texts = ["这是一个测试文本"]
            metadatas = [{"source": "test"}]
            
            print("尝试添加文本...")
            vector_store_manager.vector_store.add_texts(texts, metadatas)
            print("添加文本成功!")
            
            # 尝试搜索
            print("尝试搜索...")
            results = vector_store_manager.vector_store.similarity_search("测试", k=1)
            print(f"搜索结果: {len(results)} 个")
            for result in results:
                print(f"  内容: {result.page_content}")
                
        except Exception as e:
            print(f"直接使用向量存储时出错: {e}")
            import traceback
            traceback.print_exc()

if __name__ == "__main__":
    debug_vector_store() 